package com.atguigu.springcloud.alibaba.service.impl;

import com.atguigu.springcloud.alibaba.dao.AccountDao;
import com.atguigu.springcloud.alibaba.service.AccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sun.util.calendar.LocalGregorianCalendar;

import java.math.BigDecimal;
import java.util.concurrent.TimeUnit;

@Service
@Slf4j
public class AccountServiceImpl implements AccountService {

    @Autowired
    private AccountDao dao;

    /**
     * 扣除 账户余额
     * @param userId
     * @param money
     */
    @Override
    public void decrease(Long userId, BigDecimal money) {

        try {
            TimeUnit.SECONDS.sleep(20); // 测试异常情况
            log.info("--------->account-service中扣减账户余额开始");
            dao.decrease(userId,money);
            log.info("--------->account-service中扣减账户余额结束");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
